<template>
    <div v-loaing="loaing"></div>
</template>
<script>
import {getLoginInfo} from '@/api/triLogin'
import { setNewToken } from '@/utils/publicFun'
import { getUserMenuByUserId } from '@/utils/apis/registrationApi.js'
export default {
    data(){
        return {
loaing:false
        }
    },
    created(){
        this.tlogin()
    },
    methods: { 
        tlogin(){
            localStorage.clear()
           const code =  this.$route.query.staffCode
            if(code==='error'){
                this.$router.push('/login')
                return

            }
            const param = {
                staffCode: code
            }
            this.loaing = true
            getLoginInfo(param).then(res=> {
            this.loaing = false
            if(res.data.code ===200){
                const userInfo = {
                userId: res.data.data.SysUserInfo.userId,
                userName: res.data.data.SysUserInfo.username,
                realname:res.data.data.SysUserInfo.realname,
              }
              localStorage.userInfo = JSON.stringify(userInfo)
              setNewToken(res.data.data.token, 3600)
              this.userId = res.data.data.SysUserInfo.userId
              const parms = {
                userId: JSON.parse(localStorage.userInfo).userId
              }
              getUserMenuByUserId(parms).then((res) => {
                if (res.data.code === 200) {
                  localStorage.menuTree = JSON.stringify(res.data.data)
                  this.$router.push('/')
                }
              })

            }else {
                
                this.$router.push('/login')
                this.$message.error(res.data.message)
            }
        })
        }
    }
}
</script>
